﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Semantics;

namespace GraphBase.Presentation.SubGraph
{
    public partial class AddNodeDialog : Form
    {
        public IGraph SubGraph;
        public IGraph Graph;
        private IList<Node> Nodes;
       
        public AddNodeDialog()
        {
            InitializeComponent();
        }
        public AddNodeDialog(IGraph graph,IGraph subgraph)
        {
            this.SubGraph = subgraph;
            this.Graph = graph;
            InitializeComponent();
           

        }
        private void AddNodeDialog_Load(object sender, EventArgs e)
        {
            this.AddAllNodesToList();
        }
       
        
        /// <summary>
        /// 添加节点到List中
        /// </summary>
        public void AddAllNodesToList()
        {            
            if (this.Graph != null)
            {
                this.Nodes = this.Graph.GetAllNodes();                
            }
            if (this.Nodes.Count > 0 && this.listBox_Nodes !=null)
            {
                this.listBox_Nodes.Items.Clear();
                foreach (Node node in this.Nodes)
                {
                    if (node == (Node)this.SubGraph)
                        continue;
                    this.listBox_Nodes.Items.Add(node);
                }

            }

        }
        /// <summary>
        ///  确定将节点加入子图中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Sure_Click(object sender, EventArgs e)
        {
            Node selectedNode =(Node)this.listBox_Nodes.SelectedItem;
            if (selectedNode != null)
            {
                //((Semantics.SubGraph)this.SubGraph).SuperGraph.EnrollSubNode(this.SubGraph, selectedNode);
                this.SubGraph.EnrollNode(selectedNode);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }

            if(this.SubGraph  is Semantics .SubGraph )
            {
               
            }

        }

        private void button_Cancle_Click(object sender, EventArgs e)
        {

        }


    }
}
